package com.jp.knowledge.my.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.my.adapter.OrganizeTypeAdapter;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.business.ItemSearchBusiness;
import com.jp.knowledge.my.resources.OrganizeJoinRes;

import org.xutils.view.annotation.ViewInject;

/**
 * 加入组织
 *
 * @author gzejia 978862664@qq.com
 */
public class OrganizeJoinActivity extends SlidingActivity implements View.OnClickListener {

    @ViewInject(R.id.organize_name)
    private TextView organizeNameTv;
    @ViewInject(R.id.organize_msg)
    private TextView organizeMsgTv;
    @ViewInject(R.id.join_organize_rv_type)
    private RecyclerView mTypeRv;

    private ItemSearchBusiness mBusiness = new ItemSearchBusiness();

    @Override
    protected int getResourceId() {
        return R.layout.activity_organize_join;
    }

    @Override
    protected void init() {
        initTitle();
        initTypeRv();
        setOrganizeMsg(getIntent().getStringExtra(OrganizeJoinRes.ORGANIZED_NAME));
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.icon_left:// 返回
                finish();
                break;
        }
    }

    private void initTitle() {
//        topName.setText(R.string.join_organize_tv_main);
        topName.setText("我要创建");
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        topDesc.setVisibility(View.GONE);
        rightIcon.setVisibility(View.GONE);
        leftIcon.setOnClickListener(this);
    }

    private void setOrganizeMsg(String organizeName){
//        if(organizeName != null && organizeName.trim().length() > 0){
//            organizeNameTv.setText(String.format(getString(R.string.join_organize_tv_name), organizeName));
//            organizeMsgTv.setText(R.string.join_organize_tv_change);
//            organizeMsgTv.setTextColor(getResources().getColor(R.color.red));
//        } else{
//            organizeNameTv.setText(R.string.join_organize_tv_select);
//            organizeMsgTv.setText(R.string.join_organize_tv_hind);
//            organizeMsgTv.setTextColor(getResources().getColor(R.color.font_gray_deep));
//        }
//        organizeMsgTv.setText("请选择你要加入的组织");
        organizeMsgTv.setText("请选择你要创建组织类型");
        organizeMsgTv.setVisibility(View.GONE);
    }

    private void initTypeRv() {
        mTypeRv.setHasFixedSize(true);
        mTypeRv.setLayoutManager(new LinearLayoutManager(this));
        OrganizeTypeAdapter mTypeAdapter = new OrganizeTypeAdapter(this, mBusiness.getOrganizeType());
        mTypeAdapter.addItemClickListener(new RecycleVAdapter.OnItemClickListener() {
            @Override
            public void itemSelect(int position) {
//                Intent intent = new Intent();
//                intent.putExtra(OrganizeJoinRes.ORGANIZED_TYPE, position);
//                switch (position){
//                    case 0:
//                        intent.setClass(OrganizeJoinActivity.this, JoinCompanyActivity.class);
//                        break;
//                    case 1:
//                        intent.setClass(OrganizeJoinActivity.this, JoinSchoolActivity.class);
//                        break;
//                    case 2:
//                        intent.setClass(OrganizeJoinActivity.this, JoinZhongChuangZoneActivity.class);
//                        break;
//                    case 3:
//                        intent.setClass(OrganizeJoinActivity.this, JoinOtherOrganizeActivity.class);
//                        break;
//                }
//                startActivityForResult(intent, position);
                Intent intent = new Intent(OrganizeJoinActivity.this, CompanyCreateActivity.class);
                intent.putExtra("type", position+1);
                intent.putExtra("type", 1);
                startActivity(intent);
            }
        });
        mTypeRv.setAdapter(mTypeAdapter);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        if (resultCode != RESULT_OK || null == data)
            return;
        setOrganizeMsg(data.getStringExtra(OrganizeJoinRes.ORGANIZED_NAME));

        data.setClass(this, OrganizeActivity.class);
        setResult(RESULT_OK, data);
        finish();
    }
}
